package xyz.xtt.exchange.constants;

import java.util.Arrays;
import java.util.Objects;

import com.google.common.primitives.Ints;

/**
 * @author huqibo
 * 
 *         支付状态
 */
public enum DealStateEnum {
	NOT_PAYED(0, "未支付"), PAID(1, "已支付"), CANCEL(2, "已取消"), EXPIRE(3, "已取消"), COMPLETE(4, "已完成"), REFUNDING(5, "退款中"), REFUNDED(6, "已退款");

	private int code;
	private String desc;

	// 构造函数
	DealStateEnum(int code, String desc) {
		this.code = code;
		this.desc = desc;
	}

	public int code() {
		return code;
	}

	/**
	 * 获取描述
	 * 
	 * @return
	 */
	public String desc() {
		return desc;
	}

	public static boolean checkType(String checkType) {
		return Arrays.asList(DealStateEnum.values()).stream().anyMatch(x -> Objects.equals(x.name(), checkType));
	}

	public static DealStateEnum convert(String checkType) {
		return Arrays.asList(DealStateEnum.values()).stream().filter(x -> Objects.equals(x.name(), checkType)).findFirst().orElse(null);
	}

	public static DealStateEnum queryConvert(String checkType) {
		return Arrays.asList(DealStateEnum.values()).stream().filter(x -> Objects.equals(x.code(), Ints.tryParse(checkType))).findFirst().orElse(null);
	}
}
